package com.otojob.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.otojob.entity.Job;
import com.otojob.entity.data.JobData;
import com.otojob.service.JobService;
import com.otojob.utils.OtoException;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;

/**
 * @Description
 * @Author: TingFeng
 * @CreateTime: 2022/3/19  21:06
 */
public class JobExcelListener extends AnalysisEventListener<JobData> {
    public JobService jobService;
    public JobExcelListener(){}
    public JobExcelListener(JobService jobService) {
        this.jobService=jobService;
    }

    @Override
    public void invoke(JobData jobData, AnalysisContext analysisContext) {
        if(jobData == null) {
            throw new OtoException(20001,"文件数据为空");
        }
        Job job = new Job();
        BeanUtils.copyProperties(jobData,job);
        jobService.save(job);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
